#include <stdio.h>

int main(int argc, char *argv[])
{
	int x[10], y[10], n, m[5];
	int a, b, c, d, e, i, flag, cnt;

	scanf("%d", &n);
	for (i=0; i<n; i++) {
		scanf("%d %d", &x[i], &y[i]);
	}

	cnt = 0;
	for (a=0; a<4; a++)
	  for (b=0; b<4; b++)
		for (c=0; c<4; c++)
		  for(d=0; d<4; d++)
			for(e=0; e<4; e++) {
				m[0] = a;
				m[1] = b;
				m[2] = c;
				m[3] = d;
				m[4] = e;
				flag = 1;
				for (i=0; i<n; i++) {
					if (m[x[i]-1] == m[y[i]-1]) {
						flag = 0;
						break;
					}
				}
				if (flag) cnt++;
			}
	printf("%d\n", cnt);

	return 0;
}
